window.onload=function(){
/*logo onblur事件*/
	function odj(oTxt){
	    var oTxt=document.getElementById("txt1")
	    oTxt.onfocus=function(){
	    	if(oTxt.value=="多搜搜 ，意外惊喜等你拿"){
	    	     oTxt.value=""
	    	     oTxt.style.color="#ccc"
	    	}     
	    }
	    oTxt.onblur=function(){
	    	if(oTxt.value==""){
	    	     oTxt.value="多搜搜 ，意外惊喜等你拿"
	    	     oTxt.style.color="#ccc"
	        }
        }
     }odj(txt1)
                   
}
/*borbox 商品属性*/
$(function(){
	 $(".borbox_ula li").click(function(){
	 	var index = $(".borbox_ula li").index($(this));
	 	//console.log(index);
	 	$(".borbox_ula li").removeClass("cur");
	 	$(".borbox_ula li").eq(index).addClass("cur");
	 })
	 $(".borbox_ulb li").click(function(){
	 	var index = $(".borbox_ulb li").index($(this));
	 	//console.log(index);
	 	$(".borbox_ulb li").removeClass("cur");
	 	$(".borbox_ulb li").eq(index).addClass("cur");
	 })
})



/*JQ 分享hover事件*/
 function mhover(){
   $(function(){
	   	$(".img_lia").hover(function(){
	   		$(".dayu").css("display","block");
	   	},function(){
	   		$(".dayu").css("display","none");
	   	})
   })
}
/*JQ tab切换 tab_a*/
	function taba(){		
		$(function() {
			var $uli = $(".tab_ul li");
			var $oli = $(".tab_abox ul");
			$oli.addClass("pink_ulhide");
			$oli[0].className = "pink_ulshow";
			$uli.addClass("tab_actives");
			$uli[0].className = "tab_active";
			
			
			$uli.mouseover(function() {
				var index = $(this).index();
				$uli.removeClass().addClass("tab_actives");
				$(this).removeClass().addClass("tab_active");
				$oli.removeClass().addClass("pink_ulhide");
				$oli.eq(index).removeClass().addClass("pink_ulshow");
			});
			
		})
    } 		
			
/*JQ 放大镜切换*/
   function abc(){
	$(function() {
		 var oLi=$("#detail .w .detail_r .fangda .min_box ul li");				
		 $(oLi).mouseover(function(){
			
			var index = $("#detail .w .detail_r .fangda .min_box ul li").index($(this));
			//alert(index)
			$("#detail .w .detail_r .fangda .sbox ul").css("left",-index*260);			
		    $("#detail .w .detail_r .fangda .big_box").css("display","block");
		    	
		        var asd = index +1;
		        var picUrl = "url(../img/bgshoe"+asd+".jpg);";
		        console.log(picUrl);
	            $(".big_box").css( "background-image", "url(bgshoe"+asd+".jpg)" );	            
		});
    });
  }

/*放大镜*/
function magnifier() {	
    var scale = 4;
    
    $('.mask').mousemove(function (evt) {
        var top = evt.offsetY - $('.movebox').height() / 2;
        var left = evt.offsetX - $('.movebox').width() / 2;

        if (top < 0) {
            top = 0;
        }

        if (top > $(this).height() - $('.movebox').height()) {
            top = $(this).height() - $('.movebox').height()
        }

        if (left < 0) {
            left = 0;
        }

        if (left > $(this).width() - $('.movebox').width()) {
            left = $(this).width() - $('.movebox').width()
        }

        $('.movebox')[0].style.left = left + 'px';
        $('.movebox')[0].style.top = top + 'px';

        //process big img
        var posLeft = -(left) * scale;
        var posTop = -(top) * scale;
        $('.big_box').css('background-position', posLeft + 'px ' + posTop + 'px');


    });

    $('.mask').mouseover(function () {
        $('.movebox').show();
        $('.big_box').show();
    });
    $('.mask').mouseout(function () {
        $('.movebox').hide();
        $('.big_box').hide();
    });

    $('.mask').css({
        width: '100%',
        height: '100%'
    })
    $('.big_box').css({
        width: $('.movebox').width() * scale,
        height: $('.movebox').height() * scale
    });

    $('.big_box').css('background-size', $('.sbox').width() * scale + 'px ' + $('.sbox').height() * scale + 'px')

}

window.onload = function () {
	mhover();
	taba();
	abc();
    magnifier();
}
//滚动条
$(function(){
//评价tab切换
	   $(".judge_ul li").click(function(){
	   	var index=$(this).index();
	   	$(".judge_ul li").removeClass();
	   	$(this).addClass("l jbg");
	   	$(this).siblings().addClass("l");
	   	$(".judge_ul2 li").removeClass();
	   	$(".judge_ul2 li").eq(index).addClass("show1");
	   	$(".judge_ul2 li").eq(index).siblings().addClass("hide1");
//	   	var scroll= document.body.scrollTop||document.documentElement.scrollTop;
		var scroll=$(document).scrollTop();
			$("html,body").animate({"scrollTop":"500px"},{speed:"slow"});	
	   });
(function($) {
  jQuery.fn.scrollFix = function(height, dir) {
    height = height || 0;
    height = height == "top" ? 0 : height;
    return this.each(function() {
      if (height == "bottom") {
        height = document.documentElement.clientHeight - this.scrollHeight;
      } else if (height < 0) {
        height = document.documentElement.clientHeight - this.scrollHeight + height;
      }
      var that = $(this),
        oldHeight = false,
        p, r, l = that.offset().left;
      dir = dir == "bottom" ? dir : "top"; //默认滚动方向向下
      if (window.XMLHttpRequest) { //非ie6用fixed


        function getHeight() { //>=0表示上面的滚动高度大于等于目标高度
          return (document.documentElement.scrollTop || document.body.scrollTop) + height - that.offset().top;
        }
        $(window).scroll(function() {
          if (oldHeight === false) {
            if ((getHeight() >= 0 && dir == "top") || (getHeight() <= 0 && dir == "bottom")) {
              oldHeight = that.offset().top - height;
              that.css({
                position: "fixed",
                top: height,
                left: l
              });
            }
          } else {
            if (dir == "top" && (document.documentElement.scrollTop || document.body.scrollTop) < oldHeight) {
              that.css({
                position: "static"
              });
              oldHeight = false;
            } else if (dir == "bottom" && (document.documentElement.scrollTop || document.body.scrollTop) > oldHeight) {
              that.css({
                position: "static"
              });
              oldHeight = false;
            }
          }
        });
      } else { //for ie6
        $(window).scroll(function() {
          if (oldHeight === false) { //恢复前只执行一次，减少reflow
            if ((getHeight() >= 0 && dir == "top") || (getHeight() <= 0 && dir == "bottom")) {
              oldHeight = that.offset().top - height;
              r = document.createElement("span");
              p = that[0].parentNode;
              p.replaceChild(r, that[0]);
              document.body.appendChild(that[0]);
              that[0].style.position = "absolute";
            }
          } else if ((dir == "top" && (document.documentElement.scrollTop || document.body.scrollTop) < oldHeight) || (dir == "bottom" && (document.documentElement.scrollTop || document.body.scrollTop) > oldHeight)) { //结束
            that[0].style.position = "static";
            p.replaceChild(that[0], r);
            r = null;
            oldHeight = false;
          } else { //滚动
            that.css({
              left: l,
              top: height + document.documentElement.scrollTop
            })
          }
        });
      }
    });
  };
})(jQuery);
$(".ptop").scrollFix("top","top");


	/////cookie
	var order=[];
//	var orderItem;
	$(".jiaru").click(function(){
		//alert("1")		
//		orderItem = {};
		oImg=$(".min_box img.imgone").attr("src");
		oIzi= encodeURIComponent($(".buy_p").html());
		oColor= encodeURIComponent($(".borbox .borbox_ula .cur").html());
		oCur=parseInt($(".borbox .borbox_ulb .cur").html());
		oMoney=$(".money1").html();
		oPicval=$(".pic_val").val();
	//   var str = '{"name":"'+nameVal+'","age":"'+ageVal+'"}';
	    var orderItem = '{"img":"'+oImg+'","sizes":"'+oIzi+'","color":"'+oColor+'","cur":"'+oCur+'","money":"'+oMoney+'","price":"'+oPicval+'"}';	
		order.push(orderItem);
		console.log(orderItem);
		console.log(order);
		setCookie("order", '['+order+']',3);
		
		
	})


})









